package com.br.aiops.storage.counter;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface CounterScheduleStatusRepository extends JpaRepository<CounterScheduleStatusDTO,Integer> {

    /**
     * 查询当前周期内的统计数据
     * @param counterKey counterKey
     * @return
     */
    @Query(nativeQuery = true, value = "select * from log_alert_counter_schedule_status where counter_key = ?1")
    CounterScheduleStatusDTO findScheduleStatus(String counterKey);

    /**
     * 根据counter key查找
     * @param counterKey counterKey
     * @return
     */
    CounterScheduleStatusDTO findByCounterKey(String counterKey);

    /**
     * 根据counter key删除
     * @param key
     */
    @Query(nativeQuery = true, value = "delete from log_alert_counter_schedule_status where counter_key = ?1")
    @Modifying
    @Transactional
    void deleteByKey(String key);
}
